﻿using System;
using System.Collections.Generic;
using System.Text;
using MatlabColourConvert;
using MatlabColourConvertNative;
using MathWorks.MATLAB.NET.Arrays;
using System.Diagnostics;

namespace MatlabTest
{
    /// <summary>
    /// 色彩转换帮助类
    /// </summary>
    class ColourConvert
    {
        /// <summary>
        /// RGB转换为LAB
        /// </summary>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        public static void RgbToLab(double r, double g, double b)
        {
            // 实例化MATLAB的色彩转换类
            MatlabColourConvert.ColourCoonverts colorConvert = new MatlabColourConvert.ColourCoonverts();
            // 执行色彩转换
            MWArray result = colorConvert.RGB2Lab((MWNumericArray)r, (MWNumericArray)g, (MWNumericArray)b);
            // 将结果转换为double数组
            double[,,] result2 = (double[,,])(result.ToArray());
            // 打印结果
            Trace.WriteLine(result2.GetValue(0,0,0) + "\t" +result2.GetValue(1,0,0) + "\t" + result2.GetValue(2,0,0));
        }

        /// <summary>
        /// LAB转换为RGB
        /// </summary>
        /// <param name="L"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public static void LabToRgb(double L, double a, double b)
        {
            // 实例化MATLAB的色彩转换类
            MatlabColourConvert.ColourCoonverts colorConvert = new MatlabColourConvert.ColourCoonverts();
            // 执行色彩转换
            MWArray result = colorConvert.Lab2RGB((MWNumericArray)L, (MWNumericArray)a, (MWNumericArray)b);
            // 将结果转换为byte数组
            byte[,,] result2 = (byte[,,])(result.ToArray());
            // 打印结果
            Trace.WriteLine(result2.GetValue(0, 0, 0) + "\t" + result2.GetValue(1, 0, 0) + "\t" + result2.GetValue(2, 0, 0));
        }

    }
}
